home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1249 / mat_test.t < prev    next >
Text File  |  1997-04-18  |  2KB  |  88 lines

  1. %
  2. % "mat_test.t" demonstrats matrix functions and
  3. % related routines.
  4. %
  5. %   Sample program for the T Interpreter by:
  6. %
  7. %   Stephen R. Schmitt
  8. %   962 Depot Road
  9. %   Boxborough, MA 01719
  10. %
  11.  
  12. const DIM : int := 4
  13.  
  14. program
  15.  
  16.     var a, b, c : rmatrix
  17.     var x, y : rvector
  18.     var det : real
  19.     label program_exit :
  20.  
  21.     y[0] :=  5.0
  22.     y[1] := -1.0
  23.     y[2] :=  8.0
  24.     y[3] :=  2.0
  25.  
  26.     a[0,0] :=  2.0
  27.     a[0,1] :=  1.0
  28.     a[0,2] :=  5.0
  29.     a[0,3] :=  1.0
  30.  
  31.     a[1,0] :=  1.0
  32.     a[1,1] :=  1.0
  33.     a[1,2] := -3.0
  34.     a[1,3] := -4.0
  35.  
  36.     a[2,0] :=  3.0
  37.     a[2,1] :=  6.0
  38.     a[2,2] := -2.0
  39.     a[2,3] :=  1.0
  40.  
  41.     a[3,0] :=  2.0
  42.     a[3,1] :=  2.0
  43.     a[3,2] :=  2.0
  44.     a[3,3] := -3.0
  45.  
  46.     put "matrix A:"
  47.     print_mat( a )
  48.     det := invert( a, b, false )
  49.  
  50.     if det = 0.0 then
  51.  
  52.         put "is singular"
  53.         goto program_exit
  54.  
  55.     end if
  56.     
  57.     put "determinant of A = ", det
  58.     put "the inverse of A is:"
  59.     print_mat( b )
  60.  
  61.     put "check result:"
  62.     mul_mat_mat( a, b, c )
  63.     print_mat( c )
  64.  
  65.     put "solve A x = y"
  66.     put " for y: "
  67.     put "y0 = ", y[0]:15:6
  68.     put "y1 = ", y[1]:15:6
  69.     put "y2 = ", y[2]:15:6
  70.     put "y3 = ", y[3]:15:6
  71.  
  72.     mul_mat_vec( b, y, x )
  73.     put " solution is:"
  74.     put "x0 = ", x[0]:15:6
  75.     put "x1 = ", x[1]:15:6
  76.     put "x2 = ", x[2]:15:6
  77.     put "x3 = ", x[3]:15:6
  78.  
  79.     put "solve A = M + S, where M is symmetric and S is skew-symmetric"
  80.     sym_mat( a, b, c )
  81.     put "symmetric part"
  82.     print_mat( b )
  83.     put "skew-symmetric part"
  84.     print_mat( c )
  85.  
  86.     program_exit:
  87.  
  88. end program